const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabs:[
      {
        id:0,
        title:"正在抢购",
        active:true
      },
      {
        id:1,
        title:"开团预告",
        active:false
      },
    ],
    fiveList: [{
        img: '../../images/tb134.png',
        title: '红包转盘'
      },
      {
        img: '../../images/tb138.png',
        title: '热销推荐'
      },
      {
        img: '../../images/tb137.png',
        title: '新品上线'
      },
      {
        img: '../../images/tb136.png',
        title: '在线客服'
      },
      {
        img: '../../images/tb135.png',
        title: '商品分类'
      },
    ],
    statusBarHeight: getApp().globalData.statusBarHeight,
    rels: '', //倒计时
    hours: '',
    minutes: '',
    seconds: '',
    status: 0,
    page: 1,
    content: "",
    thumbUrl: getApp().globalData.thumbUrl
  },
send(e){

const {index} = e.detail
const {tabs} = this.data
tabs.forEach(v=>v.id == index ? v.active = true : v.active = false )
this.setData({
  tabs
})
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
    // this.time()
  },
  robGoodsDetail: function (e) {
    var id = e.currentTarget.dataset.id;
    var name = e.currentTarget.dataset.name;
    var uid = wx.getStorageSync('uid');
    if (uid) {
      wx.navigateTo({
        url: '../robGoodsDetails/robGoodsDetails?id=' + id + "&name=" + name,
      })
    } else {
      wx.navigateTo({
        url: '../authorization/authorization',
      })
    }

    console.log(e)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  countDownCallbackFn: function (e) {
    var that=this;
    var id = e.currentTarget.id;
    var param = {
      id: id
    };
    app.wxRequest('POST', "Index/checkGroupStatus", param, (res) => {
      var code=res.code;
      if(code == 1){
        setTimeout(function(){
            that.onLoad();
        },1000)
      }
    }, (err) => {
      console.log(err.errMsg)
    })
    console.log(e)
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    // var uid = wx.getStorageSync('uid');
    var param = {
      page:1
    };
    // wx.setStorageSync('uid', 1);
    app.wxRequest('POST', "Index/getMost", param, (res) => {
      var data = res.data;
      that.setData({
        groupOrderList: data,
      })
    }, (err) => {
      console.log(err.errMsg)
    })
  },
  onUnload:function(){
    var that=this;
    that.setData({
      clearTimer:true
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading();
    this.onLoad();
    wx.hideNavigationBarLoading();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    var page = that.data.page;
    //console.log(page)
    var newPage = parseInt(page) + 1;
    var param = {
      page: newPage
    };
    var groupOrderList = that.data.groupOrderList;
    app.wxRequest('POST', "Index/getMost", param, (res) => {
      var data = res.data;
      var code = res.code;
      if (code == 1) {
        that.setData({
          groupOrderList: groupOrderList.concat(data),
          page: newPage
        })
      } else {
        wx.showToast({
          title: '我是有底线的...',
          icon: "none",
          duration: 1500
        })
      }

    }, (err) => {
      console.log(err.errMsg)
    })
  },

  toclassify(e) {
    var index = e.currentTarget.dataset.index;
    if (index == 4) {
      var uid = wx.getStorageSync('uid');
      if (uid) {
        wx.switchTab({
          url: '/pages/classify/classify',
        })
      } else {
        wx.navigateTo({
          url: '/pages/authorization/authorization',
        })
      }

    } else if (index == 3) {

    } else {
      wx.showToast({
        title: '功能暂未开放,敬请期待',
        icon: "none",
        duration: 1500
      })
    }
  },
  goodsDetail: function (e) {
    // console.log(e);return false;
    var id = e.currentTarget.dataset.id;
    var gid = e.currentTarget.dataset.gid;
    var name = e.currentTarget.dataset.name;
    var uid = wx.getStorageSync('uid');
    if (!uid) {
      wx.navigateTo({
        url: '../authorization/authorization',
      })
      return false;
    }
    wx.navigateTo({
      url: '../shopDetails/shopDetails?name=' + name + "&id=" + id + "&group_id=" + gid,
    })
    // console.log(e)
  },
  getSearchContent: function (e) {
    var that = this;
    var content = e.detail.value;
    that.setData({
      content: content
    })
  },
  search_btn: function () {
    var that = this;
    var content = that.data.content;
    if (content) {
      wx.navigateTo({
        url: '../searchRes/searchRes?content=' + content,
      })
    } else {
      wx.showToast({
        title: '请输入商品名称',
        icon: "none",
        duration: 1500
      })
    }
  },
  goodsList: function (e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../robGoodsList/robGoodsList?id=' + id,
    })
  },
})